package gemini.castor.ui.server.service.impl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import gemini.castor.ui.client.service.CheckCaptchaService;

import nl.captcha.Captcha;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class CheckCaptchaServiceImpl extends RemoteServiceServlet implements
        CheckCaptchaService {

	private static final long serialVersionUID = 1L;
	
	@SuppressWarnings("unused")
	private final Log logger = LogFactory
            .getLog(CheckCaptchaServiceImpl.class);

	@Override
	public boolean performCheck(String userCaptcha) {
		HttpServletRequest request = getThreadLocalRequest();
		
		HttpSession session = request.getSession();

		Captcha captcha = (Captcha) session.getAttribute(Captcha.NAME);
		
		return captcha.isCorrect(userCaptcha);
	}
}
